package com.mcj.managementSystem.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/**
 * mp代码生成器
 */
public class CodeGenerator {
	
	public static void main(String[] args) {
		generate();
	}
	
	private static final String url = "jdbc:mysql://localhost:3306/managementsystem?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=Asia/Shanghai";
	private static final String username = "root";
	private static final String password = "123456";
	
	private static void generate() {
		FastAutoGenerator.create(url, username, password)
				.globalConfig(builder -> {
					builder.author("妙脆角") 					// 设置作者
//							.enableSwagger() 					// 开启 swagger 模式
							.fileOverride() 					// 覆盖已生成文件
							.outputDir("F:/Program/managementsystem_springboot/src/main/java/"); // 指定输出目录
				})
				.packageConfig(builder -> {
					builder.parent("com.mcj.managementSystem") 	// 设置父包名
							.moduleName("") 					// 设置父包模块名
							.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "F:/Program/managementsystem_springboot/src/main/resources/mapper")); // 设置mapperXml生成路径
				})
				.strategyConfig(builder -> {
					builder.entityBuilder().enableLombok();
					builder.mapperBuilder().enableMapperAnnotation().build();
					builder.controllerBuilder().enableHyphenStyle()// 开启驼峰转连字符
									.enableRestStyle();			// RestController
					builder.addInclude("sys_menu") 				// 设置需要生成的表名
							.addTablePrefix("t_", "sys_"); 		// 设置过滤表前缀
							
				})
//				.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
				.execute();
	}

}
